
	var phid = 'ech1',pcnoid='ecco1',pcniid='ecci1',pclz1='ec-ex',pclz2='ec-co',tgbusy=false;;

	function toggleSlideShowHide(hid,cnoid,cniid,clz1,clz2,dir,spd) {

		var hobj = document.getElementById(hid);
		var coobj = document.getElementById(cnoid);
		var ciobj = document.getElementById(cniid);
		var ho = parseInt(coobj.offsetHeight,10);
		var hi = parseInt(ciobj.offsetHeight,10);

		var phobj = document.getElementById(phid);
		var pcoobj = document.getElementById(pcnoid);
		var pciobj = document.getElementById(pcniid);
		var pho = parseInt(pcoobj.offsetHeight,10);
		var phi = parseInt(pciobj.offsetHeight,10);

		if(phid == hid) return;
		
		if(!dir) {
			dir = (coobj.style.height == 'auto')?-1:1;
			spd = dir * Math.floor(hi/10);
		}

		if(dir > 0) {
			if( ho + spd < hi ) {
				coobj.style.height = (ho + spd) + "px";
				pcoobj.style.height = (pho - spd) + "px";
				setTimeout( function() { toggleSlideShowHide(hid,cnoid,cniid,clz1,clz2,dir,spd); }, 20 );
			}
			else {
				coobj.style.height = "auto";
				pcoobj.style.height = "0px";
				hobj.className = hobj.className.replace(clz2,clz1);
				phobj.className = phobj.className.replace(clz1,clz2);
				if(phid!=hid) {
					phid = hid; pcnoid=cnoid; pcniid = cniid; pclz1 = clz1; pclz2 = clz2;
				}
			}
		} else {
			if( ho + spd > 0 ) {
				coobj.style.height = (ho + spd) + "px";
				pcoobj.style.height = (pho - spd) + "px";
				setTimeout( function() { toggleSlideShowHide(hid,cnoid,cniid,clz1,clz2,dir,spd); }, 20 );
			}
			else {
				coobj.style.height = "0px";
				pcoobj.style.height = "auto";
				hobj.className = hobj.className.replace(clz1,clz2);
				phobj.className = phobj.className.replace(clz2,clz1);

				if(phid!=hid) {
					phid = hid; pcnoid=cnoid; pcniid = cniid; pclz1 = clz1; pclz2 = clz2;
				}
			}
		}
	}

	function getFunction(hid,cnoid,cniid,clz1,clz2,dir,spd) {
		return function() { reverseToggleSlideShowHide(hid,cnoid,cniid,clz1,clz2,dir,spd); }
	}

	function reverseToggleSlideShowHide(hid,cnoid,cniid,clz1,clz2,dir,spd) {

		var hobj = document.getElementById(hid);
		var coobj = document.getElementById(cnoid);
		var ciobj = document.getElementById(cniid);
		var ho = parseInt(coobj.offsetHeight,10);
		var hi = parseInt(ciobj.offsetHeight,10);
		
		if(!dir) {
			dir = (coobj.style.height == 'auto')?-1:1;
			spd = dir * Math.floor(hi/10);
		}

		if(dir > 0) {
			if( ho + spd < hi ) {
				coobj.style.height = (ho + spd) + "px";
				setTimeout( function() { reverseToggleSlideShowHide(hid,cnoid,cniid,clz1,clz2,dir,spd); }, 20 );
			}
			else {
				coobj.style.height = "auto";
				hobj.className = hobj.className.replace(clz2,clz1);
				tgbusy=false;
			}
		} else {
			if( ho + spd > 0 ) {
				coobj.style.height = (ho + spd) + "px";
				setTimeout( function() { reverseToggleSlideShowHide(hid,cnoid,cniid,clz1,clz2,dir,spd); }, 20 );
			}
			else {
				coobj.style.height = "0px";
				hobj.className = hobj.className.replace(clz1,clz2);
				tgbusy=false;
			}
		}
	}

	
function toggleShowHide(id,arrId,isHeight) {
	var elm = document.getElementById(id);
	var arw = document.getElementById(arrId);
	var isH=!isHeight?false:true;
	if(elm) {
		var c = elm.className;
		if(isH) {
			if(c.indexOf('tshh') != -1) {
				elm.className = c.replace(" tshh",'');
				if(arw) arw.className = "tshclose";
			} else {
				elm.className = c + " tshh";
				if(arw) arw.className = "tshopen";
			}
		} else  {
			if(c.indexOf('tshw') != -1) {
				elm.className = c.replace(" tshw",'');
				if(arw) arw.className = "tshclose";
			} else {
				elm.className = c + " tshw";
				if(arw) arw.className = "tshopen";
			}
		}
	}
}

//===================================================================
// Client event attacher
//===================================================================
function addEvent(elem, type, listener) {
	if (typeof elem == 'string') {
		elem = document.getElementById(elem);
	}
	if (!elem) {
		return false;
	}
	var func = function (event) {
		var ev = event || window.event;
		var rv = listener.call(window,ev);
		if (typeof rv != 'undefined') {
			return rv;
		}
	};
	if (window.addEventListener) {
		elem.addEventListener(type,func,false); 
		return func;
	} else if (window.attachEvent) {
		elem.attachEvent("on" + type,func); 
		return func;
	}
	elem["on"+type] = func;
}

//====================================================================
// Ajax Util
//====================================================================
function AjaxService(){
	this.process = function(msg){
		if(msg.constructor != Message)
			return;
		var http = this.getXmlHttp();
		var host = "http://"+window.location.host+"/VyManagement/Ajax?svc="+msg.svc+"&request="+escape(msg.request);
		var callback = msg.callback;
		if(http){
			http.onreadystatechange = function(){
				if (http.readyState==4 && http.status==200)
				{
					var rmsg = eval("("+ http.responseText+")");
					if(callback) callback(rmsg);
				}
			};
			http.open(msg.method, host, msg.async);
			http.send();
		}
	};

	this.getXmlHttp = function() {
		var xmlhttp=null;
		
		if (window.XMLHttpRequest)
		{// code for IE7+, Firefox, Chrome, Opera, Safari
			xmlhttp=new XMLHttpRequest();
		}
		else
		{// code for IE6, IE5
			xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");
		}
		if(xmlhttp == null){
			alert("Ajax is not supported in this browser");
		}
		return xmlhttp;
	};
}

function Message(svcId){
	this.svc = svcId;
	this.method="POST";
	this.request={};
	this.response={};
	this.callback=null;
	this.async=true;
}

function MetaService(){
	this.getMeta = function(metaName, req, amap){
		var t=this, ajax = new AjaxService();
		t.amap = amap;
		var msg = new Message(metaName);
		msg.request=req;
		msg.callback=function(message){
				t.processResponse(message,req);
			};
		ajax.process(msg);
		};
	
	this.processResponse = function(message,req){
		var t=this, resp = message.response, reqMap=t.getReqMap(req),idarr,ln=0,sel;
		for(var am in t.amap){
			var data = resp[am];
			ln=0;
			if(data && t.amap[am]){
				idarr = t.amap[am].split(",");
				sel=reqMap[am.toUpperCase()];
				if(sel) sel = sel.split(",");
				for(var j=0; j< idarr.length; j++){
					//if(idarr[j]=="") continue;
					var elm = document.getElementById(idarr[j]);
					if(elm){
						if(elm.tagName.toUpperCase() == "SELECT"){
							elm.innerHTML = "";
							var opn = new Option("Select", "");
							elm.options.add(opn);
							for(var key in data){
								var opn = new Option(key, data[key]);
								if(sel && sel[ln] == data[key])
									opn.selected = true;
								elm.options.add(opn);
							}
						}else{
							elm.innerHTML = data;
						}
					}
					ln++;
				}
			}
		}
	};
	
	this.getReqMap = function(req){
		var map = {};
		var arr=req.split("&");
		for(var i=0; i < arr.length; i++){
			if(arr[i]=="") continue;
			var pair=arr[i].split("=");
			map[pair[0]]=pair[1];
		}
		return map;
	};
}

var LANG = null;
var FORM = null;
var TODAY = new Date(); 
	
function getFunc(id1, id2){
	return function() { convert_to_unicode(id1, id2); };
}

//function attachKrutiEncoding(frmName){
//	var frmElms = document.forms[frmName].elements;
//	for(var i=0; i <frmElms.length; i++) {
//		var elm = frmElms[i];
//		if(elm){
//			if(elm.tagName.toUpperCase() == "SELECT" 
//				|| elm.type == "hidden"
//				|| elm.getAttribute("sk"))
//				continue;
//			addEvent(elm.id, 'keyup', getFunc(elm.id, elm.id) );
//			addEvent(elm.id, 'blur', getFunc(elm.id, elm.id) );
//		}
//	}
//}

function attachKrutiEncoding(fldNames){
	for(var i=0; i <fldNames.length; i++) {
		var elm = document.getElementById(fldNames[i]);
		if(elm){
			if(elm.getAttribute("sk")) continue;
			addEvent(elm.id, 'keyup', getFunc(elm.id, elm.id) );
			addEvent(elm.id, 'blur', getFunc(elm.id, elm.id) );
		}
	}
}

function setLang(lng){
	LANG=lng;
	var mode =document.getElementById("mode"),
	ln =document.getElementById("lang"); 
	if(mode) mode.value="LANG";
	if(ln) ln.value=lng;
	document.forms[FORM].submit();
}

//function attachLangSupport(ln, frmName){
//	FORM = frmName;
//	LANG=ln;
//	addEvent('kruti','click',function(){ setLang('KRUTI'); });
//	addEvent('hindi','click',function(){ setLang('HINDI'); });
//	addEvent('english','click',function(){ setLang('ENGLISH'); });
//	attachKrutiEncoding(frmName);
//}

function attachLangSupport(fldNameArr){
	LANG='KRUTI';
	//addEvent('kruti','click',function(){ setLang('KRUTI'); });
	//addEvent('hindi','click',function(){ setLang('HINDI'); });
	//addEvent('english','click',function(){ setLang('ENGLISH'); });
	attachKrutiEncoding(fldNameArr);
}


function getCheckedValues(name){
	var lst = document.getElementsByName(name);
	var values = [],i=0;
	for(; i < lst.length; i++){
		if(lst[i].checked)
			values[values.length] = lst[i].value;
	}
	return values;
}

function getValues(name){
	var lst = document.getElementsByName(name);
	var values = [],i=0;
	for(; i < lst.length; i++){
		if(lst[i].value != "")
			values[values.length] = lst[i].value;
	}
	return values;
}

/*
function LangService(){
	this.processRequest = function(svcId, req){
		var t=this, ajax = new AjaxService();
		var msg = new Message(svcId);
		msg.request=req;
		msg.callback=function(message){
				t.processResponse(message);
			};
		ajax.process(msg);
		};
	
	this.processResponse = function(message){
		var t=this, resp = message.response;
	};
}

function setLanguage(lang) {
	var langSvc = new LangService();
	LANG = lang;
	langSvc.processRequest("LANGUAGE_SERVICE", {"lang" : lang});
}

*/
